package music.play.config;


import java.io.Serializable;


public class JsonResult<T> implements Serializable {
    private String message;

    private boolean success = false;

    private int code = 0;// 0:前端全局处理 -1:前端方法内自行处理

    private T data;

    private Object obj;

    public JsonResult() {
    }

    public JsonResult(boolean success, String message) {
        this.success = success;
        this.message = message;
    }

    public JsonResult(boolean success, String message, T data) {
        this.success = success;
        this.message = message;
        this.data = data;
    }

    public JsonResult(boolean success, String message, int code) {
        this.success = success;
        this.message = message;
        this.code = code;
    }

    public JsonResult(boolean success, String message, int code, T data) {
        this.success = success;
        this.message = message;
        this.code = code;
        this.data = data;
    }

    public static <T>JsonResult<T> success(String... msgStr) {
        String message;
        if (msgStr.length > 0) {
            message = msgStr[0];
        } else {
            message = "操作成功！";
        }
        return new JsonResult<T>(true, message);
    }

    public static <T> JsonResult<T> failed(String... msgStr) {
        String message;
        if (msgStr.length > 0) {
            message = msgStr[0];
        } else {
            message = "操作失败！";
        }
        return new JsonResult<>(false, message);
    }

    public static <T> JsonResult<T> failed(String message, int code) {
        return new JsonResult<>(false, message, code, null);
    }


    public String getMessage() {
        return message;
    }

    public JsonResult<T> setMessage(String message) {
        this.message = message;
        return this;
    }

    public boolean isSuccess() {
        return success;
    }

    public JsonResult<T> setSuccess(boolean success) {
        this.success = success;
        return this;
    }

    public int getCode() {
        return code;
    }

    public JsonResult<T> setCode(int code) {
        this.code = code;
        return this;
    }

    public T getData() {
        return data;
    }

    public JsonResult<T> setData(T data) {
        this.data = data;
        return this;
    }

    public Object getObj() {
        return obj;
    }

    public JsonResult<T> setObj(Object obj) {
        this.obj = obj;
        return this;
    }
}